package pattern.observer.inbuilt

import java.util.Observable

/**
 * Created by root on 15-9-17.
 */
class WeatherData extends Observable{

  private var temperature:Float = _
  private var humidity:Float = _
  private var pressure:Float = _

  def measurementsChanged(): Unit ={
    //下面两个方法都是Observable接口提供的方法，一定要先调用setChanged，否则notifyObservers会无效
    setChanged()
    notifyObservers()
  }

  def setMeasurements(temperature:Float,humidity:Float,pressure:Float): Unit ={
    this.temperature = temperature
    this.humidity = humidity
    this.pressure = pressure
    measurementsChanged()
  }

  def getTemperature(): Float ={
    return temperature
  }

  def getHumidity(): Float ={
    return humidity
  }

  def getPressure(): Float ={
    return pressure
  }
}
object WeatherData{
  def main (args: Array[String]): Unit = {
    val weatherData = new WeatherData
    val display1=new CurrentConditionsDisplay(weatherData)
    val display2=new CurrentConditionsDisplay(weatherData)
    weatherData.setMeasurements(1.0f,1.0f,1.0f)
  }
}